import Vue from "vue";
import VueRouter from "vue-router";
const Login = () => import( /* webpackChunkName: "LoginHomeWelcome" */ '../components/Login.vue')
const Home = () => import( /* webpackChunkName: "LoginHomeWelcome" */ '../components/Home.vue')
const Welcome = () => import( /* webpackChunkName: "LoginHomeWelcome" */ '../components/Welcome.vue')

// import Login from "../components/Login.vue";
// import Home from "../components/Home.vue";
// import Welcome from '../components/Welcome.vue'
// import Users from '../components/users/Users.vue'

const Users = () => import( /* webpackChunkName: "Users" */ '../components/users/Users.vue')

// import Rights from '../components/power/Rights.vue'
// import Roles from '../components/power/Roles.vue'

const Rights = () => import( /* webpackChunkName: "RightsRoles" */ '../components/power/Rights.vue')
const Roles = () => import( /* webpackChunkName: "RightsRoles" */ '../components/power/Roles.vue')

// import Cate from '../components/goods/Cate.vue'
// import Params from '../components/goods/Params.vue'
// import Goods from '../components/goods/List.vue'
// import Addgood from '../components/goods/Add.vue'

const Cate = () => import( /* webpackChunkName: "CateParamsGoodsAddgood" */ '../components/goods/Cate.vue')
const Params = () => import( /* webpackChunkName: "CateParamsGoodsAddgood" */ '../components/goods/Params.vue')
const Goods = () => import( /* webpackChunkName: "CateParamsGoodsAddgood" */ '../components/goods/List.vue')
const Addgood = () => import( /* webpackChunkName: "CateParamsGoodsAddgood" */ '../components/goods/Add.vue')

// import Reports from '../components/report/Reports.vue'
const Reports = () => import( /* webpackChunkName: "Reports" */ '../components/report/Reports.vue')
// import Orders from '../components/order/Orders.vue'
const Orders = () => import( /* webpackChunkName: "Orders" */ '../components/order/Orders.vue')






Vue.use(VueRouter);

const routes = [{
		path: "/",
		redirect: "/login",
	},
	{
		path: "/login",
		name: "Login",
		component: Login,
	},
	{
		path: "/home",
		name: "Home",
		component: Home,
		redirect: '/welcome',
		children: [{
				path: '/welcome',
				name: 'welcome',
				component: Welcome
			},
			{
				path: '/users',
				name: 'users',
				component: Users
			},
			{
				path: '/rights',
				name: 'rights',
				component: Rights
			},
			{
				path: '/roles',
				name: 'roles',
				component: Roles
			},
			{
				path: '/categories',
				name: 'categories',
				component: Cate
			},
			{
				path: '/params',
				name: 'params',
				component: Params
			},
			{
				path: '/goods',
				name: 'goods',
				component: Goods
			},
			{
				path: '/goods/add',
				name: 'add',
				component: Addgood
			},
			{
				path: '/reports',
				name: 'reports',
				component: Reports
			},
			{
				path: '/orders',
				name: 'orders',
				component: Orders
			}
		]
	},
];

const router = new VueRouter({
	routes,
});
// 挂载路由导航守卫
router.beforeEach((to, from, next) => {
	// to：要访问的路径
	// from： 从哪里来的
	// next： 放行函数  next() 放行   next('/xxxx') 强制跳转的路径
	// eslint-disable-next-line eqeqeq
	if (to.path == "/login") return next();
	// 获取token
	const tokenStr = window.sessionStorage.getItem("token");
	if (!tokenStr) return next("/login");
	next();
});

export default router;
